package com.jy.adscm.operation.hscrb.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jy.adscm.bean.system.JyUser;
import com.jy.adscm.operation.hscrb.bean.ZsProducedwaterdetail;
import com.jy.adscm.operation.hscrb.mapper.mysql.ZsProducedwaterdetailMapper;
import com.jy.adscm.operation.hscrb.service.ZsProducedwaterdetailService;
import com.jy.adscm.system.mapper.mysql.JyUserMapper;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zyl
 * @since 2018-12-18
 */
@Service
public class ZsProducedwaterdetailServiceImpl extends ServiceImpl<ZsProducedwaterdetailMapper, ZsProducedwaterdetail> implements ZsProducedwaterdetailService {
    @Autowired
    JyUserMapper jyUserMapper;
    @Override
    public Boolean updateZsProducedwaterdetail(ZsProducedwaterdetail zsProducedwaterdetail) {
        boolean result = super.updateById(zsProducedwaterdetail);
        return result;
    }

    @Override
    public List<ZsProducedwaterdetail> selectByTid(String tid) {
        Wrapper<ZsProducedwaterdetail> wrapper =new EntityWrapper<>();
        wrapper.eq("TID",tid);
        List<ZsProducedwaterdetail> zsProducedwaterdetails = super.selectList(wrapper);
        for (ZsProducedwaterdetail zsProducedwaterdetail : zsProducedwaterdetails) {
            if (AdscmBaseUtils.getInstance().isNotEmpty(zsProducedwaterdetail.getNeeder(),null)){
                JyUser jyUser = jyUserMapper.selectById(zsProducedwaterdetail.getNeeder());
                zsProducedwaterdetail.setNeederName(jyUser.getName());
            }
        }
        return zsProducedwaterdetails;
    }

    @Override
    public List<JyUser> selectUser() {
        Wrapper<JyUser> wrapper =new EntityWrapper<>();
        wrapper.setSqlSelect("id","name");
        List<JyUser> jyUsers = jyUserMapper.selectList(wrapper);
        return jyUsers;
    }
}
